package com.jing.taobao.controller.spread;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jing.system.comm.BaseController;
import com.jing.taobao.pojo.spread.TbSpreadType;
import com.jing.taobao.service.spread.TbSpreadTypeService;
import com.jing.weibo.pojo.pb.PbType;
import com.jing.weibo.pojo.user.UserInfo;

/**
 * 推广分类的Controller
 * @author jing.yue
 * @version 2012/09/29 1.0.0
 */
@Controller
public class TbSpreadTypeController extends BaseController {

	private static final Logger logger = Logger.getLogger(TbSpreadTypeController.class);

	@Autowired
	private TbSpreadTypeService tbSpreadTypeService;

	/**
	 * 根据一级ID获取子集分类列表
	 * @return
	 */
	@RequestMapping(value = "/tbSpreadType/json/findByPidTbSpreadType")
	@ResponseBody
	public ModelMap findByPidTbSpreadType(HttpServletRequest request, TbSpreadType tbSpreadType) {
		String result = null;
		List<PbType> pbTypes = null;
		UserInfo userInfo = getSessionUser(request);
		try {
			pbTypes = tbSpreadTypeService.findByPidTbSpreadType(tbSpreadType.getPid());
			result = SUCCESS;
		} catch (Exception e) {
			logger.error(userInfo.getNickname() + ": 根据一级ID获取子集分类列表异常!", e);
			result = ERROR;
		}
		ModelMap modelMap = new ModelMap();
		modelMap.put("data", pbTypes);
		modelMap.put("result", result);
		return modelMap;
	}
}